package fr.afcepf.iziticket.dao;

import java.util.List;

import fr.afcepf.iziticket.dao.interfaces.DAOSpectacleDonnees;
import fr.afcepf.iziticket.entities.SpectacleDonnees;

public class DAOSpectacleDonneesImpl extends ObjectDaoImpl<SpectacleDonnees> implements DAOSpectacleDonnees {

	public DAOSpectacleDonneesImpl()
	{
		super();
		this.setTableName("SpectacleDonnees");
	}
	
	@Override
	public SpectacleDonnees get(int paramId) {
		return (SpectacleDonnees) hibernateTemplate.get(SpectacleDonnees.class, paramId);
	}

	
	public List<SpectacleDonnees> rechercheSpectacles(String nom, String lieu, int prixMin, int prixMax){
		//or a.codePostal like '"+lieu+"%'
		String query = "from SpectacleDonnees as sd"
						+ " join sd.spectacles as s"
						+ " join s.tva as tva"
						+ " join s.theatre as t"
						+ " join t.adresse as a"
						+ " where sd.nom like '%"+nom+"%'" 
						+ " and s.puht * (1 + tva.valeurTva)>="+prixMin+" and s.puht * (1 + tva.valeurTva)<="+prixMax
						+ " and (a.ville like '%"+lieu+"%' or a.codePostal like '"+lieu+"%')";

		@SuppressWarnings("unchecked")
		List<SpectacleDonnees> list = (List<SpectacleDonnees>) hibernateTemplate.find(query);
		
		return list;
	}
}
